package com.gitee.wsl.doc.html.readability4j.extended.util

import com.gitee.wsl.doc.html.readability4j.util.RegExUtil
import com.gitee.wsl.ext.compile
import com.gitee.wsl.ext.find
import com.gitee.wsl.ext.matcher

open class RegExUtilExtended : RegExUtil {

    companion object {
        const val RemoveImageDefaultRegex = "author|avatar|thumbnail" // CHANGE: this is not in Mozilla's Readability

        const val NegativeDefaultRegexExtended = "|float"
    }


    protected val removeImage: Regex


    constructor(unlikelyCandidatesRegex: String = UnlikelyCandidatesDefaultRegex, okMaybeItsACandidateRegex: String = OkMaybeItsACandidateDefaultRegex,
                positiveRegex: String = PositiveDefaultRegex, negativeRegex: String = NegativeDefaultRegex + NegativeDefaultRegexExtended,
                extraneousRegex: String = ExtraneousDefaultRegex, bylineRegex: String = BylineDefaultRegex,
                replaceFontsRegex: String = ReplaceFontsDefaultRegex, normalizeRegex: String = NormalizeDefaultRegex,
                videosRegex: String = VideosDefaultRegex, nextLinkRegex: String = NextLinkDefaultRegex,
                prevLinkRegex: String = PrevLinkDefaultRegex, whitespaceRegex: String = WhitespaceDefaultRegex,
                hasContentRegex: String = HasContentDefaultRegex, removeImageRegex: String = RemoveImageDefaultRegex
    )
    : super(unlikelyCandidatesRegex, okMaybeItsACandidateRegex, positiveRegex, negativeRegex, extraneousRegex, bylineRegex, replaceFontsRegex, normalizeRegex,
            videosRegex, nextLinkRegex, prevLinkRegex, whitespaceRegex, hasContentRegex) {
        this.removeImage = Regex.compile(removeImageRegex)
    }


    open fun keepImage(matchString: String): Boolean { // CHANGE: this is not in Mozilla's Readability
        return !((isNegative(matchString) && !isPositive(matchString)) || removeImage.matcher(matchString).find())
    }

}